package zsc.ruanc.practicaltraining.security.auth;

import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Component;

import java.util.Collection;

/**
 *  授权用户类  实现Security类提供的UserDetails接口
 */

@Component
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class AuthUser implements UserDetails {

    private Integer id;

    private String username;

    @Override
    public String toString() {
        return "AuthUser{" +
                "id=" + id +
                ", username='" + username + '\'' +
                ", password='" + password + '\'' +
                ", role='" + role + '\'' +
                ", state=" + state +
                ", authorities=" + authorities +
                '}';
    }

    private String password;

    public String getRole() {
        return role;
    }

    private String role;



    public Integer getId() {
        return id;
    }



    private Integer state;

    // 用户的身份列表
    private Collection<? extends GrantedAuthority> authorities;


    public Integer getState() {
        return state;
    }


    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }

    @Override
    public String getPassword() {
        return password;
    }

    @Override
    public String getUsername() {
        return username;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }
}
